package com.yt.sys.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.yt.sys.common.config.YmlConfig;
import com.yt.sys.mapper.EmployeeInfoMapper;
import com.yt.sys.models.service.IEmployeeInfoService;
import com.yt.sys.models.bo.EmployeeInfoSaveBO;
import com.yt.sys.models.dto.EmployeeInfoDTO;

/**
 * 员工信息服务实现
 *
 * @author yzz
 * @Date 2025-10-22 09:44:20
 */
@DubboService
public class EmployeeInfoServiceImpl extends ServiceImpl<EmployeeInfoMapper, EmployeeInfoDTO> implements IEmployeeInfoService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(EmployeeInfoSaveBO saveBO) {
        EmployeeInfoDTO dto = new EmployeeInfoDTO();
        BeanUtils.copyProperties(saveBO,dto);
        // 注意：这里我们直接使用saveBO中的id值，而不是生成新的ID
        dto.setEmployeeId(saveBO.getId());
        // 如果saveBO中的id为空，则生成新的ID
        if (saveBO.getId() == null || saveBO.getId().isEmpty()) {
            Long id = ymlConfig.getPkId();
            dto.setEmployeeId(String.valueOf(id));
        }
        return this.insert(dto);
    }
    
    @Override
    public boolean update(EmployeeInfoSaveBO saveBO) {
        EmployeeInfoDTO dto = new EmployeeInfoDTO();
        BeanUtils.copyProperties(saveBO, dto);
        // 设置员工ID
        dto.setEmployeeId(saveBO.getId());
        // 使用updateById方法更新员工信息
        Wrapper<EmployeeInfoDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("employee_id", saveBO.getId());
        return this.update(dto, wrapper);
    }
}